<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!-- public quote -->
<%@include file="/jsp/comm_css_include.jsp"%>
<link rel="stylesheet" type="text/css" href="${basePath}/css/zTreeStyle/zTreeStyle/zTreeStyle.css">
<!doctype html>
<html>
<head>
<style type="text/css">
li{list-style: none;}

</style>
</head>
<body class="gray-bg">
<div class="container creditbody">
		 <div class="iboxtitle">
		 	<span><i class="glyphicon glyphicon-map-marker"></i>&nbsp;业务受理>签署合同</span>
         </div>
         <div class="buttonfixed">
	       <button type="button" id="save_button" class="btn dpbtn_blue btnaplly" onclick="save();">确认签署合同</button>
	    </div>
         <div class="ibox-content ibox-con">
			<form class="form-horizontal" id="commentForm">
			<input id="submitTime" name="submitTime" type="hidden" value="<fmt:formatDate value="${ywBusinessDetail.submitTime }" pattern="yyyy-MM-dd HH:mm:ss"/>" />
			<input id="realLoanAmount" name="realLoanAmount" type="hidden" value="${ywBusinessDetail.realLoanAmount }" />
			<input id="channelType" name="channelType" type="hidden" value="${ywBusinessDetail.channelType }" />
			<input id="channelTypeDisplay" name="channelTypeDisplay" type="hidden" value="${ywBusinessDetail.channelTypeDisplay }" />
			<input id="channelStatus" name="channelStatus" type="hidden" value="${ywBusinessDetail.channelStatus }" />
			<input id="channelStatusDisplay" name="channelStatusDisplay" type="hidden" value="${ywBusinessDetail.channelStatusDisplay }" />
			<!-- 业务信息 -->
			
			<%@include file="/jsp/common_yw_include.jsp"%>
			<div class="business-manwife">签署合同信息</div>			
			<div class="padding-nono">
			    <table cellpadding="0" cellspacing="0" border="0" class="buyinfor-table">
						<tr>
							<td align="right">
							    <input id="contractsRegisterId" name="contractsRegisterId" type="hidden" />
								<label class="control-label np">合同来源&版本：</label>
							</td>
							<td colspan="3">
								<input  class="form-control" type="hidden" id="parentId" name="parentId"  />
								<input  class="form-control" type="hidden" id="parentName" name="parentName" />
								<input  class="form-control" type="hidden" id="nodeId" name="nodeId" />
								<input  class="form-control" type="hidden" id="nodeNames" name="nodeNames" />
								<input  class="form-control smalliconcur smallicon" type="text" id="conVersionb" name="conVersionb" readonly placeholder="合同(必填)"/>
							</td>
						</tr>
						<tr>	
							<td align="right">
								<label class="control-label np">合同实际签署时间：</label>
							</td>
							<td>
								<input  class="smallicontm form-control shijiqs" type="text" id="beg_time" name="beg_time" placeholder="签署时间(必填)" />
								<input  class="form-control" type="text" style="display: none;" id="beg_timeb" name="beg_time" required="required"/>
							</td>
							<td align="right">
								<label class="control-label np">经办业务员：</label>
							</td>
							<td>
								<input  class="form-control" type="hidden" id="salemanId" name="salemanId" />
								<input  class="form-control smalliconcur smallicon" type="text" id="salemanName" name="salemanName"  placeholder="业务员(必填)" readonly />
							</td>
						</tr>
					</table>	
			</div>
			
			
			
		<!-- 当前经办人 -->
	    <%@include file="/jsp/comm_current_person_include.jsp"%>
		</form>
	</div>

	<div id="contractDiv" style="display: none;">
	 <div class="ibox-content" style="height: 280px;border: 1px solid #F5F5F6; overflow:auto;overflow-x: hidden;">
 			<div id="contractVersion" class="ztree">
 			</div>
 	</div>
    <div class="ibox-content">
 		    <button class="btn dpbtn_green" type="button" onclick="confirm();">确定</button>
 		    <button class="btn dpbtn_red" type="button" onclick="cancel();">取消</button>
 	</div>
 	</div>
</div>	
	
	<!-- public quote -->
    <%@include file="/jsp/comm_js_include.jsp"%>
 	<!-- 文件上传 -->
 	<%@include file="/jsp/common_fileupload_multi_include.jsp"%>
 	
 	<!-- layerDate plugin javascript -->
    <script type="text/javascript" src="${basePath}/js/plugins/layer/laydate/laydate.js"></script>

    <!--zTreeStyle.js-->
	<script type="text/javascript" src="${basePath}/js/zTreeStyle/jquery.ztree.core.js" charset="utf-8"></script>
	<script type="text/javascript" src="${basePath}/js/zTreeStyle/jquery.ztree.excheck.js" charset="utf-8"></script>
	<!-- 业务员-->
	<%@include file="/jsp/ywychoice_js_include.jsp"%>
	
	<!-- custom js -->
    
    <script type="text/javascript"></script>
    <!--
    	作者：zhangpp
    	时间：2017-04-06
    	描述：js
    -->
    <script type="text/javascript">
    
	    jQuery(function($) {  
	    	//外部js调用
		   var layDateObj = laydate({
		        elem: '#beg_time', 
		        event: 'focus',
		        istime: true 
		    });
		    $('#conVersionb').click(function(){
		    	conVersion();
		    });
		    $('#salemanName').click(function(){
		    	salemancho('',false);
		    });
		    getData();
		    getContractVersion();
	    });

		function conVersion(){
			layer.open({
				  title:'合同版本',
				  type: 1,
				  area: ['350px', '400px'], //宽高
				  content: $('#contractDiv')
			});
		}
		
		var confirm = function()
	    {
	    	 var zTree = $.fn.zTree.getZTreeObj("contractVersion"); 
	    	 var node=zTree.getSelectedNodes();
	    	 var treeNode = node[0];
	    	 if(treeNode.isParent){
	    		 layer.msg("父节点不可选择！", {icon: 5});
	    		 return;
	    	 }
	    	 
	    	 var parentNode = treeNode.getParentNode();
	    	 if(!parentNode) {
	    		 layer.msg("只能选择版本号!", {icon: 5});
	    		 return;
	    	 }
	    	 document.getElementById('parentId').value=parentNode.id;
	    	 document.getElementById('parentName').value=parentNode.name;
	    	 document.getElementById('nodeId').value=treeNode.id;
	    	 document.getElementById('nodeNames').value=treeNode.name;
	    	 document.getElementById('conVersionb').value = parentNode.name + "  " + treeNode.name;
	    	 layer.closeAll(); 
	    }
		
		var cancel = function()
	    {
		   layer.closeAll(); 
	    }
		
		//展示数据
	    function getData(){
			var busiId = $.getUrlData('id');
	    	$.dpAjax({
	    		show:false,
	    		url:'${basePath}/YwContractsRegisterController/contractsDetail',
	    		data:{busiId:busiId},
				success: function(datas){
					var data = datas.result;
					if(data) { //已经签署合同，结果不能变更
						$('.buttonfixed').hide();
						$('input').attr('readonly','readonly');
						$('#conVersionb').unbind();
						$('#salemanName').unbind();
						//我加
						$("#beg_timeb").show();
						$("#beg_time").hide();
						$('#beg_timeb').val(formateToDate(data.effectiveTime));
						//我加
						 $('#salemanName').val(data.salersmanNameThen);
						 $('#conVersionb').val(data.bankname + "  " + data.contractsName);
						
						$('#QIAN_SHU_HE_TONG').empty();
					}
					//如果已经签收合同，只是展示；如果还没有签署，则可以编辑
    				showAttentment(busiId, $('#customerId').val(), '${modeIDTypeNames.QSHT }');
	             }
	    	 });
	    }
		
		function getContractVersion(){
			$.dpAjax({
		    		show:false,
		    		url:'${basePath}/YwContractsRegisterController/queryContractVersion',
		    		data:{},
					success: function(datas){
				    	var setting = {
			 					check: {
			 						enable: false
			 					},
			 					data: {
			 						simpleData: {
			 							enable: true
			 						}
			 					},
			 					callback:
			 					{
			 						/* beforeClick: beforeClick */
			 					}
			 			};			
	     				var result = datas.result;
					    $.fn.zTree.init($("#contractVersion"), setting, result);
		             }
		    	 });	
		}
		
		//确认签署
		function save(){
			var conVersionb = $('#conVersionb').val().trim();
			if(conVersionb==""){
				layer.tips('这是必填字段', '#conVersionb');
				$("#conVersionb").focus();
				return;
			}
			
			var beg_time = $('#beg_time').val().trim();
			if(beg_time==""){
				layer.tips('这是必填字段', '#beg_time');
				$("#beg_time").focus();
				return;
			}
			
			var salemanName = $('#salemanName').val().trim();
			if(salemanName==""){
				layer.tips('这是必填字段', '#salemanName');
				$("#salemanName").focus();
				return;
			}
			
		//询问框
			var customerName = $('#customerName').text();
			var beg_time = $('#beg_time').val();
			var bankName=  $('#parentName').val();
			var nodeNames = $('#nodeNames').val();
			
			layer.confirm('客户'+customerName+'于'+ beg_time +'与 '+bankName+'签署合同，版本号：'+nodeNames, {
			  title:'确认签署合同',
			  btn: ['确认','返回修改'] //按钮
			}, function(){
				layer.closeAll();
				var data = {};
				data.busiId = $('#busiId').val();
				data.busiConfirmTime = $('#submitTime').val();
				data.loanAmount = $('#realLoanAmount').val();
				data.channelType = $('#channelType').val();
				data.channelTypeName = $('#channelTypeDisplay').val();
				data.channelStatus = $('#channelStatus').val();
				data.channelStatusName = $('#channelStatusDisplay').val();
				data.dealerName = $('#dealerName').text();
				data.departmentName = $('#orgName').text(); //。。。
				data.salersmanName = $('#salersmanName').text(); 
				data.cusName = customerName;
				data.cusIdno = $('#customerNo').text();
				data.source = $('#parentId').val();//来源
				data.bankname = bankName;
				data.contractsId = $('#nodeId').val();
				data.contractsName = nodeNames;
				data.effectiveTime = beg_time;
				data.salersmanIdThen = $('#salemanId').val();
				data.salersmanNameThen = $('#salemanName').val();
				
				$.dpAjax({
	 	    		url:'${basePath}/YwContractsRegisterController/save',
	 	    		data:data,
	     			success: function(datas){
	     				layer.msg('合同保存成功', {icon: 6,time:3000});
	     				$('.buttonfixed').hide();
						$('input').attr('readonly','readonly');
						$('#conVersionb').unbind();
						$('#salemanName').unbind();
						//我加
						$("#beg_timeb").show();
						$("#beg_time").hide();
						
						$('#beg_timeb').val(formateToDate(beg_time));
						//我加
						$('#QIAN_SHU_HE_TONG').empty();
						
						var busiId = $.getUrlData('id');
						//showAttentment(busiId, $('#customerId').val(), '${modeIDTypeNames.QSHT }');
	     				/* setTimeout(function(){
	     					location.href='${basePath}/web/system/yw/signContract.jsp'; 
	     				 },3000);  */
	                 }
	 	    	});
			}, function(){
				layer.closeAll();
			});
		}
    </script>
</body>
</html>
